package com.warmheart.core.util;

import com.warmheart.base.entity.BaseEntity;
import com.warmheart.core.enums.DELETED;

/**
 * @ClassName: EntityCommonCopyUtil
 * @Description: 给处于服务中的实体类通用字段赋值
 * @author ZhangJianyang
 * @date 2025-06-16 09:37:02
 *
 */
public class EntityCommonCopyUtil {

    /**
     * 
     * @Title: addOld2AddNew
     * @Description: 原始添加对象到新添加对象
     * @author ZhangJianyang
     * @param oldEntity
     * @param newEntity
     * @return
     */
    public static <T extends BaseEntity<?, ?>> T addOld2AddNew(T oldEntity, T newEntity) {
        if (oldEntity == null || newEntity == null) {
            return newEntity;
        }
        newEntity.setCreateBy(oldEntity.getCreateBy());
        newEntity.setCstCreate(oldEntity.getCstCreate());
        newEntity.setUpdateBy(oldEntity.getCreateBy());
        newEntity.setCstModify(oldEntity.getCstCreate());
        newEntity.setDelFlag(DELETED.DELETED_NO.getValue());
        return newEntity;
    }

    /**
     * 
     * @Title: addOld2UpdateNew
     * @Description: 原始添加对象到新更新对象
     * @author ZhangJianyang
     * @param oldEntity
     * @param newEntity
     * @return
     */
    public static <T extends BaseEntity<?, ?>> T addOld2UpdateNew(T oldEntity, T newEntity) {
        if (oldEntity == null || newEntity == null) {
            return newEntity;
        }
        newEntity.setUpdateBy(oldEntity.getCreateBy());
        newEntity.setCstModify(oldEntity.getCstCreate());
        return newEntity;
    }

    /**
     * 
     * @Title: updateOld2AddNew
     * @Description: 原始更新对象到新添加对象
     * @author ZhangJianyang
     * @param oldEntity
     * @param newEntity
     * @return
     */
    public static <T extends BaseEntity<?, ?>> T updateOld2AddNew(T oldEntity, T newEntity) {
        if (oldEntity == null || newEntity == null) {
            return newEntity;
        }
        newEntity.setCreateBy(oldEntity.getUpdateBy());
        newEntity.setCstCreate(oldEntity.getCstModify());
        newEntity.setUpdateBy(oldEntity.getUpdateBy());
        newEntity.setCstModify(oldEntity.getCstModify());
        newEntity.setDelFlag(DELETED.DELETED_NO.getValue());
        return newEntity;
    }

    /**
     * 
     * @Title: updateOld2UpdateNew
     * @Description: 原始更新对象到新更新对象
     * @author ZhangJianyang
     * @param oldEntity
     * @param newEntity
     * @return
     */
    public static <T extends BaseEntity<?, ?>> T updateOld2UpdateNew(T oldEntity, T newEntity) {
        if (oldEntity == null || newEntity == null) {
            return newEntity;
        }
        newEntity.setUpdateBy(oldEntity.getUpdateBy());
        newEntity.setCstModify(oldEntity.getCstModify());
        return newEntity;
    }

    /**
     * 
     * @Title: copyConfig2Add
     * @Description: 设置专用复制配置属性到新建对象
     * @author HQKJ
     * @param oldEntity
     * @param newEntity
     * @return
     */
    public static <T extends BaseEntity<?, ?>> T copyConfig2Add(T oldEntity, T newEntity) {
        if (oldEntity == null || newEntity == null) {
            return newEntity;
        }
        newEntity.setCreateBy(oldEntity.getUpdateBy());
        newEntity.setCstCreate(oldEntity.getCstModify());
        newEntity.setUpdateBy(oldEntity.getUpdateBy());
        newEntity.setCstModify(oldEntity.getCstModify());
        newEntity.setDelFlag(DELETED.DELETED_NO.getValue());
        return newEntity;
    }

    /**
     * 
     * @Title: copyConfig2Update
     * @Description: 设置专用复制配置属性到编辑对象
     * @author HQKJ
     * @param oldEntity
     * @param newEntity
     * @return
     */
    public static <T extends BaseEntity<?, ?>> T copyConfig2Update(T oldEntity, T newEntity) {
        if (oldEntity == null || newEntity == null) {
            return newEntity;
        }
        newEntity.setUpdateBy(oldEntity.getUpdateBy());
        newEntity.setCstModify(oldEntity.getCstModify());
        return newEntity;
    }

}
